package com.txsj.scan.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.txsj.scan.R;
import com.txsj.scan.adapter.SettledGoodsAdapter;
import com.txsj.scan.base.BaseActivity;
import com.txsj.scan.bean.GoodsInfo;
import com.txsj.scan.presenter.SettledGoodsPresenter;
import com.txsj.scan.utils.GsonFactory;
import com.txsj.scan.view.ISettledGoodsView;
import com.txsj.scan.widget.TitleBarView;
import com.txsj.scan.widget.dialog.LabelIntroduceDialog;

import java.util.List;

/**
 * Created by wangchuangjun on 2018/12/7
 * Desc: 已结算商品界面
 */

public class SettledGoodsActivity extends BaseActivity<SettledGoodsPresenter> implements ISettledGoodsView {

    private RecyclerView recyclerView;
    private SettledGoodsAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settled_goods);
        initView();
        initData();
    }

    private void initData() {
        if (null == getIntent() && null == getIntent().getStringExtra("data"))return;
        String json = getIntent().getStringExtra("data");
        List<GoodsInfo> list = GsonFactory.getObjectList(json,GoodsInfo.class);
        adapter.setList(list);
    }

    private void initView() {
        mTitle = (TitleBarView) findViewById(R.id.mTitle);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL,false));
        adapter = new SettledGoodsAdapter(this);
        recyclerView.setAdapter(adapter);

        mTitle.setRightOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new LabelIntroduceDialog(SettledGoodsActivity.this).show();
            }
        });
    }

    @Override
    protected SettledGoodsPresenter providePresenter() {
        return new SettledGoodsPresenter(this);
    }

    @Override
    public Context context() {
        return this;
    }

}
